package vn.game;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;

public class ExtTextView extends TextView {
	private String tag = "ExtTextView";
	private Canvas cvs;
	private String num;
	private boolean drawText;
	private boolean bg;
	private int idx;
	private boolean black;

	public ExtTextView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		drawText = false;
		bg = false;
		num = "";
		black = false;
		setGravity(Gravity.CENTER);
		setTextSize(18);
		setBackgroundColor(Color.DKGRAY);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		try {
			cvs = canvas;
			Paint paint = new Paint();
			if (drawText) {
				if (black)
					paint.setColor(Color.BLACK);
				else
					paint.setColor(Color.BLUE);
				canvas.drawText(num, 1, 10, paint);
				// Log.i(tag, "draw" + num);
			}
			if (bg) {
				paint.setColor(Color.DKGRAY);
				canvas.drawRect(0, 0, 100, 100, paint);
			}
			paint.setColor(Color.BLACK);
			canvas.drawLine(0, 0, 0, 100, paint);
			super.onDraw(canvas);
		} catch (Exception ex) {
			// Log.i(tag, ex.getMessage());
		}
	}

	public void onDrawText(String num) {
		try {
			this.num = num;
			drawText = true;
			this.black = false;
			bg = false;
			onDraw(cvs);
		} catch (Exception ex) {
			Log.i(tag + "drawText1", ex.getMessage());
		}
	}

	public void onDrawText(String num, boolean black) {
		try {
			this.black = black;
			this.num = num;
			drawText = true;
			bg = false;
			onDraw(cvs);
		} catch (Exception ex) {
			Log.i(tag + "DrawText2", ex.getMessage());
		}
	}

	public void onDrawBackground(boolean bg) {
		try {
			this.bg = bg;
			drawText = false;
			onDraw(cvs);
		} catch (Exception ex) {
			Log.i(tag + "onDrawBackground", ex.getMessage());
		}
	}

	public void setIdx(int idx) {
		this.idx = idx;
	}

	public int getIdx() {
		return idx;
	}

}